home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / FDF101.ARJ / ELIB.ZOO / input.c < prev    next >
C/C++ Source or Header  |  1992-04-30  |  689b  |  39 lines

  1. #include <ctype.h>
  2. #include <stdio.h>
  3.  
  4.  
  5.  
  6. /*
  7.  * skip_whitespace
  8.  *
  9.  * given a string pointer, skip the whitespace and return the pointer to
  10.  * the new spot.
  11.  */
  12. char *skip_whitespace(char *str)
  13.  
  14. {
  15.     while (isspace(*str))
  16.         str++;
  17.  
  18.     return str;
  19. }
  20.  
  21.  
  22.  
  23. /*
  24.  * zap_trailing_nl
  25.  *
  26.  * on strings which have been read in using fgets(), take out the trailing
  27.  * newline.  If no newline, read the input stream until one is encountered.
  28.  */
  29. void zap_trailing_nl(char *str, int max_ch, FILE *stream)
  30.  
  31. {
  32.     int i = strlen(str), ch;
  33.  
  34.     if ((i > 0) && (str[i-1] == '\n'))
  35.         str[i-1] = '\0';
  36.     else if (i >= max_ch)
  37.         while (((ch = getc(stream)) != EOF) && (ch != '\n'));
  38. }
  39.